package collection.map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapLoopSample {

    public static void doForLoop(Map map) {
        Set<String> keys = map.keySet();
        for (String k : keys) {
            System.out.println(k + ":" + map.get(k));
        }
    }

    public static void doForEach(Map map) {
        map.forEach((k, v) -> {
            System.out.println(k + ":" + v);
        });
    }

    public static void doIterator(Map map) {
        Iterator<Map.Entry<String, Object>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Object> entry = iterator.next();
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
    }

    public static void main(String[] args) {
        Map<String, Object> student = new HashMap<>();
        student.put("name", "dz");
        student.put("age", 18);
        student.put("height", 182);
        student.put("weight", 60);
        System.out.println(student);

        doForLoop(student);
        doForEach(student);
        doIterator(student);

    }
}
